//
//  photoSecondViewController.m
//  旅游咨询
//
//  Created by 高建 on 15/4/18.
//  Copyright (c) 2015年 xubin. All rights reserved.
//

#import "photoSecondViewController.h"

@interface photoSecondViewController ()

@end

@implementation photoSecondViewController

- (void)viewWillAppear:(BOOL)animated
{
    [self.navigationController setNavigationBarHidden:NO];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self.navigationController setNavigationBarHidden:NO];
    
     self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:(UIBarButtonItemStylePlain) target:self action:@selector(popViewRootViewController)];
    
    UICollectionViewFlowLayout *flowLayOut = [[UICollectionViewFlowLayout alloc] init];
    flowLayOut.itemSize = CGSizeMake(WidthZ * 0.2933, HeighZ * 0.165);
    flowLayOut.sectionInset = UIEdgeInsetsMake(WidthZ * 0.04, HeighZ * 0.0225, WidthZ * 0.02666, HeighZ * 0.0225);
    flowLayOut.scrollDirection = UICollectionViewScrollDirectionVertical;
    flowLayOut.minimumInteritemSpacing = 3;
    
    //集合视图
    UICollectionView *myCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, WidthZ, HeighZ - 64) collectionViewLayout:flowLayOut];
    [self.view addSubview:myCollectionView];
    myCollectionView.backgroundColor = [UIColor whiteColor];
    myCollectionView.delegate = self;
    myCollectionView.dataSource = self;
    [myCollectionView release];
   
//
    //注册cell
    [myCollectionView registerClass:[PhotoSecondCollectionViewCell class] forCellWithReuseIdentifier:@"reuse"];
    
    [MyAFNData getNetData:[NSString stringWithFormat:@"http://api.breadtrip.com/destination/place/5/%@/photos/?start=0&count=21&gallery_mode=true",self.SecondId] responseGETData:^(id data) {
        self.SecondPhotoArray = [NSMutableArray array];
        NSMutableArray *array = [data objectForKey:@"items"];
        
        for (NSMutableDictionary *InLandDic in array) {
            SecondPhotoModel *myPhotoModel = [[SecondPhotoModel alloc] init];
            [myPhotoModel setValuesForKeysWithDictionary:InLandDic];
            [self.SecondPhotoArray addObject:myPhotoModel];
            [myPhotoModel release];
            
        }
        [myCollectionView reloadData];
        
        
    }];
        
    

}
- (void)popViewRootViewController
{
    [self.navigationController popViewControllerAnimated:YES];
    [self.navigationController setNavigationBarHidden:YES];
}

//显示item上的内容
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    PhotoSecondCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuse" forIndexPath:indexPath];

    cell.backgroundColor = [UIColor whiteColor];
//
    //改变边框形状
    cell.PhotoImageView.layer.masksToBounds = YES;
    cell.PhotoImageView.layer.cornerRadius = 3;
    
    SecondPhotoModel *secondPhoto = [self.SecondPhotoArray objectAtIndex:indexPath.row];
    //    NSLog(@"++++++++++++++++_+++++++++%@",myPhotoModel);
    cell.secondModel = secondPhoto;
   
    
    
    
    return cell;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    SecondImageViewController *SecondeVc = [[SecondImageViewController alloc]init];
    SecondeVc.FirstCramePhotoArray = self.SecondPhotoArray;
    SecondeVc.index = indexPath.row;
    [self.navigationController pushViewController:SecondeVc animated:YES];
    
    
    
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.SecondPhotoArray.count;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
